<?php

class Userinfo extends CI_Controller{
	
	private $user_ifno;

	public function __construct()
	{
		parent::__construct();
		//登录校验
		$this->common->check_login();
		//user_model
		$this->user_info = $this->user->get_user_info_id($_SESSION['user']['id']);//$_SESSION['user'];//1;

	}

	/**
	 * 修改个人信息
	 */
	public function index()
	{

		$this->load->helper('form');

		$data['user'] = $this->user_info;

		$data['left'] = $this->load->view('left', '', TRUE);

		$data['menu'] = $this->load->view('menu', '', TRUE);

		$this->load->view('userinfo',$data);

	}

	/**
	 * 个人信息提交
	 */
	public function info_post()
	{
		if(empty($_POST))
		{
			exit($this->common->alert_msg_goback('参数错误'));
		}

		$id = $this->user_info['id'];
		//二级密码校验
		$check = $this->user->check_spwd($id,md5($_POST['spwd']));

		if(empty($check))
		{
			exit($this->common->alert_msg_goback('二级密码错误'));
		}

		$result = $this->user->update_userinfo($id);

		if($result)
		{
			exit($this->common->alert_msg_url('更新成功',site_url('userinfo')));			
		}
		else
		{
			exit($this->common->alert_msg_goback('更新失败'));
		}
	}
}